package com.decisiontree.swing;

import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Smith Tsang
 * @since 0.85
 *
 */
public class FileSettings extends javax.swing.JPanel {

    JFileChooser fc;

    /** Creates new form FileSettings */
    public FileSettings() {
        initComponents();
        fc = new JFileChooser();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        trainingBrowse = new javax.swing.JButton();
        trainingLabel = new javax.swing.JLabel();
        trainDescriptionLabel = new javax.swing.JLabel();
        testingBrowse = new javax.swing.JButton();
        testingDataLabel = new javax.swing.JLabel();
        enableTestingBox = new javax.swing.JCheckBox();
        testDescriptionLabel = new javax.swing.JLabel();
        trainingField = new javax.swing.JTextField();
        testingField = new javax.swing.JTextField();
        proceedButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Select Data Sets"));
        setMinimumSize(new java.awt.Dimension(500, 300));
        setLayout(new java.awt.GridBagLayout());

        trainingBrowse.setText("Browse");
        trainingBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trainingBrowseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 5, 3);
        add(trainingBrowse, gridBagConstraints);

        trainingLabel.setText("Training Data Set:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 4, 5, 4);
        add(trainingLabel, gridBagConstraints);

        trainDescriptionLabel.setText("Type in the training data in the following text field or browse from your computer.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        add(trainDescriptionLabel, gridBagConstraints);

        testingBrowse.setText("Browse");
        testingBrowse.setEnabled(false);
        testingBrowse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                testingBrowseActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        add(testingBrowse, gridBagConstraints);

        testingDataLabel.setText("Testing Data Set:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(3, 5, 3, 5);
        add(testingDataLabel, gridBagConstraints);

        enableTestingBox.setText("Specify Testing Data Set");
        enableTestingBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                enableTestingBoxActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        add(enableTestingBox, gridBagConstraints);

        testDescriptionLabel.setText("If you have testing data, you may enable the check box and type in your testing dataset.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 3, 5);
        add(testDescriptionLabel, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 5, 3);
        add(trainingField, gridBagConstraints);

        testingField.setEnabled(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        add(testingField, gridBagConstraints);

        proceedButton.setText("Proceed");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        add(proceedButton, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 7;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        add(jLabel1, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

    private void trainingBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trainingBrowseActionPerformed

         int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                trainingField.setText(file.getAbsolutePath());
            } else {

          }
    }//GEN-LAST:event_trainingBrowseActionPerformed

    private void testingBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testingBrowseActionPerformed
                 int returnVal = fc.showOpenDialog(this);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                testingField.setText(file.getAbsolutePath());
            } else {

          }
    }//GEN-LAST:event_testingBrowseActionPerformed

    private void enableTestingBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableTestingBoxActionPerformed

           testingField.setEnabled(enableTestingBox.isSelected());
           testingBrowse.setEnabled(enableTestingBox.isSelected());
    }//GEN-LAST:event_enableTestingBoxActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox enableTestingBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton proceedButton;
    private javax.swing.JLabel testDescriptionLabel;
    private javax.swing.JButton testingBrowse;
    private javax.swing.JLabel testingDataLabel;
    private javax.swing.JTextField testingField;
    private javax.swing.JLabel trainDescriptionLabel;
    private javax.swing.JButton trainingBrowse;
    private javax.swing.JTextField trainingField;
    private javax.swing.JLabel trainingLabel;
    // End of variables declaration//GEN-END:variables


        public static void main(String args[]){
        JFrame frame = new JFrame("Specify Data Sets");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (InstantiationException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        } catch (UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }

        frame.add(new FileSettings());
        frame.setSize(500,300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        frame.setPreferredSize(new Dimension(300,200));
        frame.setVisible(true);


    }

}
